import instance from '@/utils/axios.js'

//1.获取所有频道的列表
function getChannelList () {
  return instance({
    url: '/v1_0/channels',
    method: 'get'
  })
}

//导出
export { getChannelList }

//2.获取新闻推荐
//对象形式
function getArticlesList ({ channel_id, timestamp }) {
  return instance({
    url: '/v1_0/articles',
    method: 'GET',
    params: {
      with_top: 1,
      channel_id,
      timestamp
    }
  })
}

//导出
export { getArticlesList }

//3.获取文章详情数据
function getArticleInfo ({ id }) {
  return instance({
    url: `/v1_0/articles/${id}`,
    method: 'GET'
  })
}

//导出
export { getArticleInfo }

//4.关注与不关注
//关注
function followUser (id) {
  return instance({
    method: 'post',
    url: '/v1_0/user/followings',
    data: {
      target: id
    }
  })
}
//不关注
function unFollowUser (id) {
  return instance({
    method: 'DELETE',
    url: `/v1_0/user/followings/${id}`
  })
}

//导出
export { followUser, unFollowUser }

//5.点赞与不点赞
//点赞
function addPraise (id) {
  return instance({
    method: 'post',
    url: '/v1_0/article/likings',
    data: {
      target: id
    }
  })
}
//不点赞
function cancelPraise (id) {
  return instance({
    method: 'DELETE',
    url: `/v1_0/article/likings/${id}`
  })
}

//导出
export { addPraise, cancelPraise }


//6.不喜欢与取消不喜欢
//不喜欢
function addDisLike (id) {
  return instance({
    method: 'post',
    url: '/v1_0/article/dislikes',
    data: {
      target: id
    }
  })
}
//取消不喜欢
function cancelDisLike (id) {
  return instance({
    method: 'DELETE',
    url: `/v1_0/article/dislikes/:${id}`
  })
}

//导出
export { addDisLike, cancelDisLike }


// 搜索推荐词
function getSuggestion (keyword) {
  return instance({
    method: 'get',
    url: `http://toutiao-app.itheima.net/v1_0/suggestion`,
    params: {
      q: keyword
    }
  })
}
//导出
export { getSuggestion }


// 搜索结果接口
function getSearchList ({page,per_page,q}) {
  return instance({
    method: 'get',
    url: '/v1_0/search',
    params: {
      page,
      per_page,
      q,
    }
  })
}
//导出
export { getSearchList }